<template>
  <div class="modal fade" id="addAuditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <h4 class="modal-title" id="myModalLabel"> 楼盘审核</h4>
        </div>
        <div class="modal-body">
          <div class="form-horizontal">
            <div class="form-group">
              <label class="col-md-4 col-sm-2 control-label"><span class="required">*</span>楼盘状态：</label>
              <div class="col-md-8 col-sm-10">
                <select class="form-control" v-model="audit.premisesStatus">
                  <option value="1">审核通过</option>
                  <option value="2">审核拒绝</option>
                </select>
              </div>
            </div>
            <div class="form-group">
              <label for="" class="col-sm-4 control-label">审核备注：</label>
              <div class="col-sm-8">
                <textarea rows="5" class="form-control" v-model="audit.remark" placeholder="请填写审核备注"></textarea>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <!--<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>-->
          <button type="button" class="btn checkedBtn" v-show="btnShow" @click="saveAudit">确定</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  //接收父组件的绑定值
  props: ["auditModal"],
  data() {
    return {
      //机构信息对象
      audit: {
        premisesStatus: "1",
        remark: "",
      },
      btnShow: true,
    };
  },
  watch: {},
  methods: {
    saveAudit() {
      var _self = this;
      _self.btnShow = false;
      var body = {};
      body.params = {
        id: this.auditModal.premisesId,
        premisesStatus: _self.audit.premisesStatus,
        remark: _self.audit.remark,
      };
      var url = this.utilHelper.apiUrl + "/api/auditPremises";
      _self.$http.post(url, body).then(
        (response) => {
          var resData = response.body.resData;
          if (resData.result == "1") {
            $("#addAuditModal").modal("hide");
            //子组件向父组件传递信号: 调用父组件中对子组件的监听
            _self.$emit("saveAuditListener");
            layer.msg("审核成功", { time: 2000 }, () => {
              _self.btnShow = true;
            });
          } else {
            layer.msg(resData.errorMsg);
            _self.btnShow = true;
          }
        },
        (response) => {
          layer.msg("审核失败", { time: 2000 }, () => {
            _self.btnShow = true;
          });
        }
      );
    },
  },
};
</script>